﻿using System;
using System.IO;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace Peter.Logic
{
   /// <summary>
   /// View model for the image viewer.
   /// </summary>
   public class ImageViewModel
   {
      private readonly FileInfo m_FileInfo;

      /// <summary>
      /// Initializes a new image viewer model.
      /// </summary>
      /// <param name="pathToImage">Path to the image to load.</param>
      public ImageViewModel (string pathToImage)
      {
         this.m_FileInfo = new FileInfo (pathToImage);
      }

      /// <summary>
      /// Gets the file name of the image.
      /// </summary>
      public string FileName
      {
         get { return this.m_FileInfo.Name; }
      }

      /// <summary>
      /// Gets the file path of the image.
      /// </summary>
      public string FilePath
      {
         get { return this.m_FileInfo.FullName; }
      }

      /// <summary>
      /// Gets the image to display.
      /// </summary>
      public ImageSource ImageSource
      {
         get
         {
            if (this.m_FileInfo.Exists)
            {
               var image = new BitmapImage ();
               image.BeginInit ();
               image.UriSource = new Uri (this.m_FileInfo.FullName);
               image.EndInit ();

               return image;
            }

            return null;
         }
      }
   }
}
